﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Diagnostics;
using System.Windows.Forms;
using Contract;
using System.IO;

namespace Service
{
    public partial class frmServer : Form
    {
        ICallBack Proxy;
        public frmServer()
        {
            InitializeComponent();

            // create a hosting process for CalculatorService
            ServiceHost host = new ServiceHost(typeof(DataUploader));

            NetTcpBinding binding = new NetTcpBinding();
            binding.TransferMode = TransferMode.Streamed;
            binding.ReceiveTimeout = TimeSpan.MaxValue;
            binding.MaxReceivedMessageSize = long.MaxValue;

            host.AddServiceEndpoint(typeof(IDataUploader), binding,
            new Uri("net.tcp://localhost:5000/DataUploader"));

            host.Open();
            label1.Text = "Service is started.";

        }

        private void frmServer_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //////////////////////////////////////
            NetTcpBinding binding = new NetTcpBinding();
            binding.TransferMode = TransferMode.Streamed;
            binding.SendTimeout = TimeSpan.MaxValue;
            binding.MaxReceivedMessageSize = 1000;
            binding.PortSharingEnabled = true;

            EndpointAddress address = new EndpointAddress("net.tcp://localhost:8000/CallBack");

            ChannelFactory<ICallBack> channel = new ChannelFactory<ICallBack>(binding, address);
            Proxy = channel.CreateChannel();
            ///////////////////////////////////////////////
            Proxy.SendMessageToClient(textBox1.Text);
        }
    }
}
